import { Inject, Post, Body } from '@midwayjs/core';
import { CoolController, BaseController } from '@cool-midway/core';
import { StudentStudentProfileEntity } from '../../entity/studentProfile';
import { StudentStudentProfileService } from '../../service/studentProfile';
import { BaseSysUserEntity } from '../../../base/entity/sys/user';
import { StudentStudentEntity } from '../../entity/student';

/**
 * 学生档案控制器
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: StudentStudentProfileEntity,
  service: StudentStudentProfileService,
  insertParam: ctx => {
    return {
      createUserId: ctx.admin.userId,
    };
  },
  pageQueryOp: {
    keyWordLikeFields: ['a.remark'],
    fieldEq: ['a.studentId'],
    select: [
      'a.*',
      'b.name as studentName',
      'c.name as createUserName',
      'd.name as updateUserName',
    ],
    join: [
      {
        entity: StudentStudentEntity, // 假设studentId关联的是UserInfoEntity
        alias: 'b',
        condition: 'a.studentId = b.id',
        type: 'leftJoin',
      },
      {
        entity: BaseSysUserEntity,
        alias: 'c',
        condition: 'a.createUserId = c.id',
        type: 'leftJoin',
      },
      {
        entity: BaseSysUserEntity,
        alias: 'd',
        condition: 'a.updateUserId = d.id',
        type: 'leftJoin',
      },
    ],
  },
})
export class AdminStudentStudentProfileController extends BaseController {
  @Inject()
  studentStudentProfileService: StudentStudentProfileService;

  /**
   * 软删除
   * @param id
   */
  @Post('/reportSoftDelete')
  async reportSoftDelete(@Body('id') id: number) {
    return this.ok(await this.studentStudentProfileService.reportSoftDelete(id));
  }

  /**
   * 根据学员id返回检查数据
   * @param studentId
   */
  @Post('/getCheckDataByStudentId')
  async getCheckDataByStudentId(@Body('studentId') studentId: number) {
    return this.ok(await this.studentStudentProfileService.getCheckDataByStudentId(studentId));
  }
}
